﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ADF.BaseClasses;

namespace SZ
{
    public class OpenAttribute : BaseCommand
    {
        private IMapControl3 m_MapControl = null;
        private MainFrm m_mainFrm = null;

        public OpenAttribute(MainFrm mainFrm)
        {
            base.m_caption = "打开图层属性表";
            m_mainFrm = mainFrm;
        }

        public override void OnClick()
        {
            #region

            try
            {
                ILayer Layer = (ILayer)m_MapControl.CustomProperty;
                if (Layer == null)
                {
                    MessageBox.Show("请选择图层或检查图层是否损坏！", "", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    return;
                }

                AttributeTable m_attrTable = new AttributeTable(m_MapControl, Layer);
                m_attrTable.Owner = m_mainFrm;
                m_attrTable.Show();
            }
            catch
            {
                MessageBox.Show ("无法打开属性表，请检查所选图层数据是否损坏！","",MessageBoxButtons.OK ,MessageBoxIcon.Error ,MessageBoxDefaultButton .Button1 );
                return;
            }

            #endregion
        }

        public override void OnCreate(object hook)
        {
            m_MapControl = (IMapControl3)hook;
        }
    }
}
